安装 Kubersphere 和 Kubernetes
关闭swap
sudo swapoff -a # 临时
sudo sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久
根据规划设置主机名
# 在192.168.192.180执行
sudo hostnamectl set-hostname ubuntu-k8s-master
# 在192.168.192.181执行
sudo hostnamectl set-hostname ubuntu-k8s-node1
# 在192.168.192.182执行
sudo hostnamectl set-hostname ubuntu-k8s-node2
# 在192.168.192.183执行
sudo hostnamectl set-hostname ubuntu-k8s-node3
添加hosts
cat <<EOF | sudo tee /etc/hosts
192.168.192.180 ubuntu-k8s-master
192.168.192.181 ubuntu-k8s-node1
192.168.192.182 ubuntu-k8s-node2
192.168.192.183 ubuntu-k8s-node3
10.123.123.180 ubuntu-k8s-master
10.123.123.181 ubuntu-k8s-node1
10.123.123.182 ubuntu-k8s-node2
10.123.123.183 ubuntu-k8s-node3
EOF
将桥接的IPv4流量传递到iptables的链
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
# 设置所需的 sysctl 参数,参数在重新启动后保持不变
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
# 应用 sysctl 参数而不重新启动
sudo sysctl --system
lsmod | grep br_netfilter
lsmod | grep overlay
sudo sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables net.ipv4.ip_forward
# 如果init时仍提示iptables错误请执行
echo "1">/proc/sys/net/bridge/bridge-nf-call-iptables
echo "1">/proc/sys/net/ipv4/ip_forward
时间同步
sudo apt install chrony -y
sudo systemctl start chrony && sudo systemctl enable chrony
安装 Kubernetes
1.安装Kubersphere和Kubernetes的依赖组件 。
所有节点都安装
sudo apt install socat conntrack ebtables ipset -y
在其中一个节点执行:
2.下载KuberKey,并设置地域为中国,以免无法正常访问Google或Github。
export KKZONE=cn
# 下载并执行sh命令
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.1.6 sh -
如果上面下载不了就先下载downloadKubekey.sh之后再手动执行sh
wget https://github.com/kubesphere/kubekey/releases/download/v1.1.0/downloadKubekey.sh --no-check-certificate
sudo apt install mblaze -y
export VERSION=v3.1.6
sh downloadKubekey.sh
下载完成后当前目录下将生成 KubeKey 二进制文件 kk。
执行以下命令为 KubeKey 二进制文件 kk 添加执行权限:
chmod +x kk
执行以下命令创建安装配置文件 k8s-v1288.yaml:
./kk create config -f k8s-v1288.yaml --with-kubernetes v1.28.8
#./kk create config --with-kubernetes v1.28.8 --with-kubesphere v3.4.0 -f config.yaml
命令执行完毕后将生成安装配置文件 k8s-v1288.yaml。
vim k8s-v1288.yaml
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: ubuntu-k8s-master, address: 192.168.192.180, internalAddress: 192.168.192.180, user: wengtx, password: 密码}
- {name: ubuntu-k8s-node1, address: 192.168.192.181, internalAddress: 192.168.192.181, user: wengtx, password: 密码}
- {name: ubuntu-k8s-node2, address: 192.168.192.182, internalAddress: 192.168.192.182, user: wengtx, password: 密码}
- {name: ubuntu-k8s-node3, address: 192.168.192.183, internalAddress: 192.168.192.183, user: wengtx, password: 密码}
roleGroups:
etcd:
- ubuntu-k8s-master
control-plane:
- ubuntu-k8s-master
worker:
- ubuntu-k8s-node1
- ubuntu-k8s-node2
- ubuntu-k8s-node3
controlPlaneEndpoint:
#internalLoadbalancer: haproxy # 如需部署⾼可⽤集群,且⽆负载均衡器可⽤,可开启该参数,做集群内部负载均衡
domain: lb.kubesphere.local
# vip
address: ""
port: 6443
kubernetes:
version: v1.28.2
clusterName: cluster.local
autoRenewCerts: true
containerManager: containerd
etcd:
type: kubekey
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
#enableMultusCNI: false
registry:
registryMirrors: []
insecureRegistries: []
addons: []
./kk create cluster -f k8s-v1288.yaml
安装 KubeSphere
KubeSphere Core (ks-core) 是 KubeSphere 的核心组件,为扩展组件提供基础的运行环境。KubeSphere Core 安装完成后,即可 访问 KubeSphere Web 控制台。
curl -k --resolve raw.githubusercontent.com:443:185.199.108.133 https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
在集群节点,执行以下命令安装 KubeSphere Core。
helm upgrade --install -n kubesphere-system --create-namespace ks-core https://charts.kubesphere.io/main/ks-core-1.1.2.tgz --debug --wait --set global.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks --set extension.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks